<template>
	<payModal />
</template>

<script>
	import payModal from "@/components/payModal.vue";
	import request from "@/request/request.js"
	
	export default{
		async onLoad(option) {
			// 检查是否存在book_id或open_book_id参数
			let params = {...option};
			
			try {
				// 如果存在open_book_id，通过API获取真实book_id
				if (option.book_id) {
					// 使用request函数调用API
					const response = await request("douYinBook/originBook", {
						data: {
							open_book_id: option.book_id
						}
					});
					
					// 检查API响应
					if (response && response.status_code === 200 && response.data && response.data.book_id) {
						// 使用API返回的真实book_id
						params.id = response.data.book_id;
						// 删除原来的open_book_id参数
						delete params.book_id;
						console.log('获取到真实book_id:', params.id);
					} else {
						console.error('API返回数据格式不正确:', response);
					}
				}
				
				const queryString = new URLSearchParams(params).toString();
				console.log(queryString,"queryString");
				
				uni.redirectTo({
					url: `/pages/Detail/Detail?${queryString}`
				});
			} catch (error) {
				console.error('获取book_id出错:', error);
				// 出错时仍然使用原始参数进行跳转
				const queryString = new URLSearchParams(option).toString();
				uni.redirectTo({
					url: `/pages/Detail/Detail?${queryString}`
				});
			}
		}
	}
</script>

